// logs.js
/* const util = require('../../utils/util.js') */
/* import {
  loadingShow,
  loadingHide
} from "../../utils/util"; */
import {
  ApiPatientCardList,
  ApiGetArticleList,
  ApiGetSet
} from "../../api/index"
const app = getApp()
Page({
  data: {
    active: '在线问诊',
    $path: app.globalData.$path,
    menuRight: app.globalData.menuRight,
    menuTop: app.globalData.menuTop,
    menuHeight: app.globalData.menuHeight,
    cateInfo: 0,
    cateType: [{
        name: "慢病预防",
        id: "慢病预防"
      },
      {
        name: "心理健康",
        id: "心理健康"
      },
      {
        name: "中医养生",
        id: "中医养生"
      }
    ]
  },
  onLoad() {
    app.globalData.loadingShow()
  },

  onShow() {
    /*    wx.showLoading({
         title: '加载中',
         mask: true
       }) */

    this.getTabBar().init();
    app.globalData.loadingHide()
    if (wx.getStorageSync('token')) {
      this.getPatient()
    }
    this.getSet()
    this.getArticle('慢病预防')
  },

  cateClick(e) {
    console.log(e)
    let articleData = e.currentTarget.dataset
    this.setData({
      cateInfo: articleData.info
    })
    this.getArticle(articleData.v.name)
  },
  articleClick(e) {
    console.log(e)
    wx.setStorageSync('articleData', e.currentTarget.dataset.v)
    wx.navigateTo({
      url: `/pages/articleDetail/index`,
    })
  },

  getArticle(title) {
    ApiGetArticleList({
      cate: title
    }).then(res => {
      this.setData({
        articleList: res.data
      })
    })
  },
  getPatient() {
    ApiPatientCardList().then(res => {
      let useData = res.data.find(item => {
        return item.use == '1'
      })
      console.log(useData)

      this.setData({
        patientArr: res.data,
        useData: useData ? useData : {}
      })
    })
  },
  getChangeData(e) {
    this.getPatient()
  },
  onClickData(e) {
    //在线问诊
    let value = e.currentTarget.dataset.v
    this.setData({
      active: value
    })

  },
  getSet(){
    ApiGetSet().then(res => {
      this.setData({
        getSet: res.data
      })
    })
  },

  //添加就诊人
  addPatient() {
    wx.navigateTo({
      url: '/pages/patientCard/index?type=1',
    })
  },
  //切换就诊人
  changePatient(e) {
    this.setData({
      showpopup: true
    })
  },


  onChange(event) {
    console.log(event)
    this.setData({
      active: event.detail.title
    })
    /*    wx.showToast({
         title: `切换到标签 ${event.detail.name}`,
         icon: 'none',
       }); */
  },

})